package com.yipei.business.controller;

import com.yipei.business.domain.MlManagementAccount;
import com.yipei.business.service.IMlManagementAccountService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 管理账号Controller
 *
 * @author yipei
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/business/managementaccount")
@Api(tags = "管理账号", description = "管理账号管理")
public class MlManagementAccountController extends BaseController {
    @Autowired
    private IMlManagementAccountService mlManagementAccountService;

    /**
     * 查询管理账号列表
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:list')")
    @ApiOperation("管理账号获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlManagementAccount mlManagementAccount) {
        startPage();
        List<MlManagementAccount> list = mlManagementAccountService.selectMlManagementAccountList(mlManagementAccount);
        return getDataTable(list);
    }

    /**
     * 导出管理账号列表
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:export')")
    @ApiOperation("管理账号导出数据")
    @Log(title = "管理账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlManagementAccount mlManagementAccount) {
        List<MlManagementAccount> list = mlManagementAccountService.selectMlManagementAccountList(mlManagementAccount);
        ExcelUtil<MlManagementAccount> util = new ExcelUtil<MlManagementAccount>(MlManagementAccount.class);
        util.exportExcel(response, list, "管理账号数据");
    }

    /**
     * 获取管理账号详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:query')")
    @ApiOperation("管理账号通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlManagementAccountService.selectMlManagementAccountById(id));
    }

    /**
     * 新增管理账号
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:add')")
    @ApiOperation("管理账号新增数据")
    @Log(title = "管理账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlManagementAccount mlManagementAccount) {
        return toAjax(mlManagementAccountService.insertMlManagementAccount(mlManagementAccount));
    }

    /**
     * 修改管理账号
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:edit')")
    @ApiOperation("管理账号修改数据")
    @Log(title = "管理账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlManagementAccount mlManagementAccount) {
        return toAjax(mlManagementAccountService.updateMlManagementAccount(mlManagementAccount));
    }

    /**
     * 删除管理账号
     */
    //@PreAuthorize("@ss.hasPermi('business:managementaccount:remove')")
    @ApiOperation("管理账号删除数据")
    @Log(title = "管理账号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlManagementAccountService.deleteMlManagementAccountByIds(ids));
    }
}
